1461A - String Generation - CodeForces Solution


constructive algorithms greedy *800

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, k = list(map(int, input().split()))
    a = ''
    for i in range(n):
        if i % 3 == 0:
            a += 'a'
        elif i % 3 == 1:
            a += 'b'
        else:
            a += 'c'
    print(a)

C++ Code:

//阶梯式的自由元不在最后几行
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define double long double
const ll N = 2e5+9 ;
const ll INF = 1e18 ;
const ll mod = 1e9 ;
//const double pi = acos(-1) ;
const double eps = 1e-9 ;
ll gcd( ll a , ll b ){ return a == 0 ? b : gcd( b%a , a ) ; }
ll lcm( ll a , ll b ){ return (a/gcd(a,b))*b ; }
void solve(){
    ll n , m ; cin >> n >> m ;
    for( int i = 0 ; i < n ; i ++ ){
        if( i%3 == 0 ) cout << 'a' ;
        if( i%3 == 1 ) cout << 'b' ;
        if( i%3 == 2 ) cout << 'c' ;
    }
    cout << "\n" ;
}
int main(){
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    ll tt = 1 ; cin >> tt ;
    while( tt-- ) solve() ;
    return 0 ;
}
/*

3 3
1 1 0
0 1 1
1 1 1

*/
 	  	 		     	   		   			 	   	


Comments

Submit
0 Comments
More Questions

118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted
387. First Unique Character in a String
383. Ransom Note
242. Valid Anagram
141. Linked List Cycle
21. Merge Two Sorted Lists
203. Remove Linked List Elements
733. Flood Fill
206. Reverse Linked List
83. Remove Duplicates from Sorted List
116. Populating Next Right Pointers in Each Node
145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree
112. Path Sum
1556A - A Variety of Operations
136. Single Number
169. Majority Element
119. Pascal's Triangle II